
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import JCP.Browser;
import JCP.JavaClientPage;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Pham
 */
public class Home extends JPanel implements JavaClientPage {

    protected Browser br;
    protected Map<String, Object> parameters;
    public Map<String, String> setItem = new HashMap<>();
    JTextField field;
    JButton button;
    JTextArea link;
    JTextArea textArea;
    JMenu menuBody;
    ArrayList<JMenu> menuList;

    public Home() {
    }
    public JPanel JavaClientPage = new JPanel();

    @Override
    public JPanel getBody() {
     setItem.put("name", "Sy");
     setItem.put("Tom", "Kaka");
     // setItem.put("Link", "Kend");
        br.localstorage(setItem);
     // JLabel locallb = new JLabel("Value is: " + br.localstorage("name"));
     //   JLabel locallb = new JLabel("Value is: " + br.localstorage("name")+br.localstorage("Tom"));
      JLabel locallb = new JLabel("Value is: " + br.localstorage("name")+" "+br.localstorage("Tom")+" "+br.localstorage("Link"));
        
        JavaClientPage.add(locallb);
        //ImageIcon icon = new ImageIcon("Logo2.png");
  ImageIcon icon = new ImageIcon(this.getClass().getResource("/Logo2.png"));
        //Image iconload = icon.getImage();
       
    JLabel lbicon = new JLabel(icon);
    JavaClientPage.add(lbicon);

        JMenu home = new JMenu("Home");
        JMenu contactus = new JMenu("Contact us");
        JMenu bioraphy = new JMenu("Bioraphy");
        JMenu gallery = new JMenu("Gallery");
        JMenuItem homeOpen = new JMenuItem("Open");
        JMenuItem homeClose = new JMenuItem("Close");
        home.add(homeOpen);
        home.add(homeClose);
        menuList = new ArrayList<>();
        menuList.add(home);
        menuList.add(contactus);
        menuList.add(bioraphy);
        menuList.add(gallery);
        br.setMenu(menuList);

        homeOpen.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               // System.out.println("This from mouse");
            }
        });

        home.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                br.go("http://localhost/Home");
            }
        });

        contactus.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                br.go("http://localhost/ContacUs");
            }
        });

        link = new JTextArea("Effective Java");
        link.setBackground(Color.GRAY.brighter());
        link.setForeground(Color.BLUE);
        Font font = new Font("Verdana", Font.BOLD, 14);
        link.setFont(font);
        link.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                br.go("http://localhost/Tester?name=Toan&city=London");
            }
        });
        link.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                //System.out.println("Enter!");
                link.setCursor(new Cursor(Cursor.HAND_CURSOR));
                link.setForeground(Color.YELLOW);
                link.setToolTipText("Effective Java (2nd Edition) (Java Series)");
            }
        });

        link.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseExited(MouseEvent e) {
               // System.out.println("Exit!");
                link.setForeground(Color.BLUE);
            }
        });

        JavaClientPage.add(link);
        textArea = new JTextArea(5, 40);
        JCheckBox checkbox = new JCheckBox("Male", true);
        JavaClientPage.add(checkbox);
        JavaClientPage.add(textArea);
        return JavaClientPage;
    }

    @Override
    public void setBrowser(Browser br) {
        this.br = br;
    }

    @Override
    public void setParameters(Map<String, Object> parameters) {
        this.parameters = parameters;
    }
}
